#include<unistd.h>
#include<fcntl.h>
#include<string.h>
#include<sys/stat.h>
#include<stdlib.h>
#include<stdio.h>
#include<errno.h>
int main(int argc,char** argv)
{
    int fd1=open(argv[1],O_RDWR);
    int fd2=open(argv[2],O_RDWR);
    printf("--------fd1=%d,fd2=%d\n--------",fd1,fd2);

    int newfd=dup2(fd1,fd2);
    printf("---------fd1=%d,fd2=%d,newfd=%d\n",fd1,fd2,newfd);

//通过newfd对文件test1进行修改
//    write(newfd,"hello linux\n",strlen("hello linux\n"));

    write(fd2,"hello linux\n",strlen("hello linux\n"));//fd2 在dup后指向dup对应的文件地址

    

    close(fd1);
    close(fd2);

return 0;
}
